package com.jolink.omiis.wechat.api.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.JsonObject;
import com.jolink.omiis.wechat.api.IAccountOperationApi;
import com.jolink.omiis.wechat.util.GsonUtil;

public class AccountOperationApiImpl extends WeChatApiBaseService implements IAccountOperationApi {

	private static Logger logger = LoggerFactory.getLogger(AccountOperationApiImpl.class);

	@Override
	public Map<String, String> createTempQrcode(Map<String, String> reqParmas) {
		long t1 = System.currentTimeMillis();
		String baseUri = QRCODE_CREATE;
		// String baseUri = "https://api.weixin.qq.com/cgi-bin/qrcode/create?";
		JsonObject rootJson = new JsonObject();
		rootJson.addProperty("expire_seconds", "604800");
		rootJson.addProperty("action_name", "QR_SCENE");
		JsonObject scene = new JsonObject();
		scene.addProperty("scene_id", reqParmas.get("sceneId"));
		JsonObject actionInfo = new JsonObject();
		actionInfo.add("scene", scene);
		rootJson.add("action_info", actionInfo);
		Map<String, String> req = new HashMap<String, String>();
		req.put("access_token", reqParmas.get("accessToken"));
		String httpEntity = GsonUtil.jsonElement2Json(rootJson);
		String jsonResult = executePost(baseUri, req, httpEntity);
		Map<String, String> resultMap = GsonUtil.str2Map(jsonResult);
		logger.info("调用腾讯接口返回结果：{}，str2Map：{}。", jsonResult, resultMap);
		if (resultMap.containsKey("errcode")) {
			logger.error("生成临时二维码失败，错误信息：{}。", resultMap);
			return resultMap;
		}
		String baseUri2 = "";
		long t2 = System.currentTimeMillis();
		logger.info("创建临时二维码完成，耗时：{}毫秒。", (t2 - t1));
		return resultMap;
	}

	@Override
	public Map<String, String> createPermanentQrcode(Map<String, String> reqParams) {
		return null;
	}

	@Override
	public Map<String, String> transferLongUrl2ShortUrl(Map<String, String> reqParams) {
		return null;
	}

}
